﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.Materials;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;

using T.E.ERP.Read.API.Applicantions.Command.MaterialsCommand.QueryMaterialsCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.MaterialsCommandCommand.QueryMaterialsCommandHandler
{
    /// <summary>
    /// 供应方式查询处理方法
    /// </summary>
    public class SupplyMethodQueryCommandHandler:IRequestHandler<SupplyMethodQueryCommand,APIResult<List<SupplyMethodModel>>>
    {
        /// <summary>
        /// 供应方式仓储接口
        /// </summary>
        private readonly IBaseRepository<SupplyMethodModel> sRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="sRepo"></param>
        public SupplyMethodQueryCommandHandler(IBaseRepository<SupplyMethodModel>sRepo)
        {
            this.sRepo = sRepo;
        }
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<List<SupplyMethodModel>>> Handle(SupplyMethodQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SupplyMethodModel>> result = new APIResult<List<SupplyMethodModel>>();
            var list = sRepo.GetAll().Result;
            result.data = list.ToList();
            result.Msg = APIEnum.查询成功.ToString();
            result.Code = APIEnum.成功;
            result.Count = list.Count();
            return Task.FromResult(result);

        }
    }



}
